package com.college.products.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.college.common.pojo.ao.DeliveryAddress;
import com.college.common.pojo.dto.products.AddDeliveryAddressDTO;
import com.college.common.pojo.dto.products.QueryDeliveryAddressDTO;
import com.college.common.pojo.dto.products.UpdateDeliveryAddressDTO;
import com.college.common.pojo.model.page.PageParamRequest;
import com.college.common.response.CommonResult;
import com.college.common.utils.object.ObjectUtil;
import com.college.products.mapper.DeliveryAddressMapper;
import com.college.products.service.DeliveryAddressService;
import com.github.pagehelper.page.PageMethod;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 收货地址 服务实现类
 * @author 小C工作室
 * @since 2025-02-22
 */
@Service
public class DeliveryAddressServiceImpl extends ServiceImpl<DeliveryAddressMapper, DeliveryAddress> implements DeliveryAddressService {
    @Autowired
    private DeliveryAddressMapper deliveryAddressMapper;

    @Override
    public List<DeliveryAddress> queryList(QueryDeliveryAddressDTO queryDeliveryAddressDTO) {
        return deliveryAddressMapper.queryList(queryDeliveryAddressDTO);
    }

    @Override
    public List<DeliveryAddress> queryListPage(QueryDeliveryAddressDTO queryDeliveryAddressDTO, PageParamRequest pageParamRequest) {
        PageMethod.startPage(pageParamRequest.getPage(), pageParamRequest.getLimit());
        return deliveryAddressMapper.queryList(queryDeliveryAddressDTO);
    }

    @Override
    public CommonResult<String> addDeliveryAddress(AddDeliveryAddressDTO addDeliveryAddressDTO) {
        return this.save(addDeliveryAddressDTO)? CommonResult.success("收货地址新增成功") : CommonResult.failed("收货地址新增失败");
    }

    @Override
    public CommonResult<String> updateDeliveryAddress(UpdateDeliveryAddressDTO updateDeliveryAddressDTO) {
        DeliveryAddress deliveryAddress = ObjectUtil.objectCopyProperties(updateDeliveryAddressDTO, DeliveryAddress.class);
        return this.updateById(deliveryAddress) ? CommonResult.success("收货地址修改成功") : CommonResult.failed("收货地址修改失败");
    }
}
